-
Notifications
You must be signed in to change notification settings - Fork 622
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce separate thread pool for establishing Initiator connections #255
Conversation
* Fixes #254 * introduced separate thread pool with 3 threads for connection establishment * changed `enabled` flag in `Session` to `volatile` and removed synchronization from `setEnabled`/`isEnabled` since I could not find any good reason why it was synchronized ** `volatile` should ensure that all threads should see the current state and prevents possible deadlocks now that flag is checked from distinct threads * removed `synchronized` from `IoSessionInitiator.ConnectTask.run()` since I could not find any good reason why it was synchronized
to test LGTM check
…j/quickfixj into connection-timeout-254
AbstractSessionConnectorBuilder
- by default 3 threads are used - changed executor to be non-static, i.e. each Initiator instance has its own reconnect thread pool - (unless feature is disabled which will use the former behaviour) - to use the former behaviour (i.e. use "QFJ Timer" thread for both reconnections and calls to next()) you should pass 0 as number of reconnect threads - when passing 1 you will end up with a separate thread for reconnections; next() will still be called by "QFJ Timer" thread
super(settings, sessionFactory); | ||
IoBuffer.setAllocator(new SimpleBufferAllocator()); | ||
IoBuffer.setUseDirectBuffer(false); | ||
if (numReconnectThreads > 0) { | ||
scheduledReconnectExecutor = Executors.newScheduledThreadPool(numReconnectThreads, new QFScheduledReconnectThreadFactory()); | ||
((ThreadPoolExecutor) scheduledReconnectExecutor).setMaximumPoolSize(numReconnectThreads); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting maximumPoolSize
to initialPoolSize
ensures that numReconnectThreads
threads are available to service tasks. Otherwise new threads only get created when the task queue is full.
@@ -318,7 +318,7 @@ protected void startSessionTimer() { | |||
if (shortLivedExecutor != null) { | |||
timerTask = new DelegatingTask(timerTask, shortLivedExecutor); | |||
} | |||
sessionTimerFuture = scheduledExecutorService.scheduleAtFixedRate(timerTask, 0, 1000L, | |||
sessionTimerFuture = SCHEDULED_EXECUTOR.scheduleAtFixedRate(timerTask, 0, 1000L, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not directly related to this change, but we probably don't want to queue up timer tasks if they take too long for some reason.
quickfixj/quickfixj-core/src/main/java/quickfix/mina/initiator/IoSessionInitiator.java
Line 364 in e53d41b
.scheduleWithFixedDelay(reconnectTask, 0, 1, TimeUnit.SECONDS); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reconnectTasks
timed out after a maximum of 2000ms. That was the reason to have a bigger pool to service these requests, see #254 .
What do you suggest to prevent piling up these tasks?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to IoSessionInitiator
. As a rule of thumb scheduleWithFixedDelay
is better in majority of cases than scheduleAtFixedRate
. It respects the delay, but it only reschedules when the tasks finishes - this does not allow bursts if for some reason task is slow.
…quickfix-j#255) * Fixes quickfix-j#254 * introduced separate thread pool with 3 threads for connection establishment * changed `enabled` flag in `Session` to `volatile` and removed synchronization from `setEnabled`/`isEnabled` since I could not find any good reason why it was synchronized ** `volatile` should ensure that all threads should see the current state and prevents possible deadlocks now that flag is checked from distinct threads * removed `synchronized` from `IoSessionInitiator.ConnectTask.run()` since I could not find any good reason why it was synchronized * - prevent NPE on Logon in Session when not specifying messageFactory in AbstractSessionConnectorBuilder * - added possibility to specify number of reconnect threads via builder - by default 3 threads are used - changed executor to be non-static, i.e. each Initiator instance has its own reconnect thread pool - (unless feature is disabled which will use the former behaviour) - to use the former behaviour (i.e. use "QFJ Timer" thread for both reconnections and calls to next()) you should pass 0 as number of reconnect threads - when passing 1 you will end up with a separate thread for reconnections; next() will still be called by "QFJ Timer" thread
Fixes #254
enabled
flag inSession
tovolatile
and removed synchronization fromsetEnabled
/isEnabled
since I could not find any good reason why it was synchronized**
volatile
should be enough to ensure that all threads see the current state now that it is checked from distinct threadssynchronized
fromIoSessionInitiator.ConnectTask.run()
since I could not find any good reason why it was synchronized